var pomelo = require("pomelo");
var routeUtil = require("./app/util/routeUtil");
var sync = require("pomelo-sync-plugin");

var app = pomelo.createApp();// 创建
app.set("name", "godate-server");// 设置服务器名称

// 全局配置
app.configure("production|development", function () {
	app.route("chat", routeUtil.chat);// 路由配置
	app.loadConfig("mysql", app.getBase() + "/./config/mysql.json"); // 载入mysql配置文件
	app.filter(pomelo.timeout());// 配置过滤器
});

// 配置连接负载
app.configure("production|development", "connector", function () {
	app.set("connectorConfig",
		{
			connector: pomelo.connectors.hybridconnector,
			heartbeat: 3,
			useDict: true,
			useProtobuf: true
		});
});

// 配置网关
app.configure("production|development", "gate", function () {
	app.set("connectorConfig",
		{
			connector: pomelo.connectors.hybridconnector,
			useProtobuf: true
		});
});

// 配置mysql
app.configure("production|development", "connector|chat", function () {
	console.log("app.configure: mysql.");
	var dbclient = require("./app/dao/mysql/mysql").init(app);
	app.set("dbclient", dbclient);
	app.use(sync, { sync: { path: __dirname + "/app/dao/mapping", dbclient: dbclient } });
});

app.start();// 启动服务器

// 异常捕捉
process.on("uncaughtException", function (err) {
	console.error(" Caught exception: " + err.stack);
});